package com.tlgen.service;

import com.tlgen.mapper.RecordMapper;
import com.tlgen.model.Record;
import com.tlgen.model.RespPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author: tlgen
 * @Discription:
 */
@Service
public class RecordService {

    @Autowired
    RecordMapper recordMapper;

    public RespPageBean getRecordByPage(Integer page, Integer size, Record record) {
        if (page != null && size != null) {
            page = (page-1) * size;
        }
        List<Record> data = recordMapper.getRecordByPage(page, size, record);
        Long total = recordMapper.getTotal(record);
        RespPageBean bean = new RespPageBean();
        bean.setData(data);
        bean.setTotal(total);
        return bean;
    }

    public Integer addRecord(Record record) {
        record.setStartDate(new Date());
        return recordMapper.insertSelective(record);
    }

    public Integer deleteRecordById(Integer id) {
        return recordMapper.deleteByPrimaryKey(id);
    }

    public Integer updateRecord(Record record) {
        record.setEndDate(new Date());
        return recordMapper.updateByPrimaryKeySelective(record);
    }
}
